﻿@using QDT.Common
@using QDT.Core
@using QDT.Core.Projects
@model QDT.Common.IPagedList<QDT.Core.Projects.Project>
@{
    Func<ProjectStatus, string> FormatStatus = x =>
        {
            switch (x)
            {
                case ProjectStatus.Full:
                    return "<span style='color:red;'>" + ProjectStatus.Full.ToLocalizable() + "</span>";
                default:
                    return x.ToLocalizable();
            }
        };
    Func<ProjectStatus, string> StatusChange = x =>
        {
            switch (x)
            {
                case ProjectStatus.Wait:
                    return "进行中";
                case ProjectStatus.Full:
                    return "还款中";
                default:
                    return "";
            }
        };
}
@section HeadSection {

    @Html.IncludeCSS("~/Content/Css/calendar.css")
    @Html.IncludeScript("~/Content/JS/calendar.js")
    @Html.IncludeCSS("~/Content/Css/jquery-calendar.css")
    @Html.IncludeScript("~/Content/JS/jquery-calendar.js")

    <script type="text/javascript">

        function show_detail(projectId) {

            var url = '@Url.Action("ShowDetail")' + '?id=' + projectId;

            showAjaxResult(url, "借款详细统计", 700, 400);
        }

        function change_status(projectId) {

            var url = '@Url.Action("ChangeStatus")' + '?id=' + projectId;

            showAjaxResult(url, "编辑项目状态", 700, 400);
        }

    </script>
}

<div class="main_title">
    贷款列表</div>
<div class="blank5">
</div>
<div class="button_row">
    @Html.ActionLink("新增", "AddProject", new {}, new {@class = "button"})
    @*    <a class="button" href="javascript: del()">删除</a>*@
</div>
<div class="blank5">
</div>
<div class="search_row">
    <form name="search" action="@Url.Action("Easy")" method="get">	
        编号：<input type="text" class="textbox" name="projectId" value="@Request.Params["projectId"]" size="8"/>
        贷款名称：<input type="text" class="textbox" name="name" value="@Request.Params["name"]"/>
        分类:
        <select name="typeID">
            <option value="-1">所有分类</option>
            @foreach (ProjectType type in ViewData["ProjectTypes"] as IList<ProjectType>)
            {
                <option value="@type.ID">@type.Name</option>
            }
        </select>
        用户名：<input type="text" class="textbox" name="username" value="@Request.Params["username"]"/>
        贷款状态
        <select name="dealStatus">
            <option value="" selected="selected">所有状态</option>
            <option value="0">等待材料</option>
            <option value="1">进行中</option>
            <option value="2">流标</option>
            <option value="3">满标</option>
            <option value="4">还款中</option>
            <option value="5">已还清</option>
        </select>
        担保公司<select id="agencyid" name="agencyid" >
            <option value="0">请选择</option>
            <option value="1">贵州烽凌投资担保有限公司</option>
            <option value="2">贵州金顶汇担保有限公司</option>
            <option value="3">贵州国信中小投资担保有限公司</option>
            <option value="4">遵义市城投融资担保有限责任公司</option>
            <option value="5">鼎盛鑫融资担保有限公司</option>
        </select>
        开始日期：<input type="text" class="textbox" id="start" name="start" value="@Request.Params["start"]" onfocus=" this.blur(); return showCalendar('start', '%Y-%m-%d', false, false, 'start');" size="8"/>
	    结束日期：<input type="text" class="textbox" id="end" name="end" value="@Request.Params["end"]" onfocus=" this.blur(); return showCalendar('end', '%Y-%m-%d', false, false, 'end');" size="8"/>
        期限：<input type="text" class="textbox" name="repayTime" value="@Request.Params["repayTime"]" size="8"/>
        <input type="submit" class="button" value="搜索"/>
    </form>
</div>
<div class="grid_box">
    <div class="grid_top">
    </div>
    @Html.Grid(Model).Columns(column =>
        {
            column.CheckBox(x => x.ID);
            column.For(x => x.ID).Named("编号").HeaderAttributes(style => "width:50px;");
            column.For(x => Html.ActionLink(x.Name, "EditProject", new {id = x.ID})).Named("贷款名称").SortColumnName("Name");
            column.For(x => x.CreateTime).Named("创建时间").HeaderAttributes(style => "width:180px;").SortColumnName("CreateTime");
            column.For(x => Html.F().GetPrjectTypeName(x.TypeID)).Named("贷款类型").SortColumnName("TypeID");
            column.For(x => x.RepayTime + "月").Named("期限").SortColumnName("RepayTime");
            column.For(x => Html.F().GetUserName(x.UserID)).Named("借款人").SortColumnName("UserID");
            column.For(x => x.BorrowAmount.ToMoney()).Named("借款资金").SortColumnName("BorrowAmount");
            column.For(x => FormatStatus(x.Status)).Named("投标状态").SortColumnName("InnerStatus").Encode(false);
            column.Buttons(btns => btns.Add(x => Html.ScriptLink(StatusChange(x.Status), "change_status({0})", x.ID))
                .Add(x => Html.ActionLink(x.IsOffline && x.Status.Equals(ProjectStatus.Progress) ? "投资" : " ", "OfflineInvest", new { projectId = x.ID })));
            column.For(x => string.IsNullOrWhiteSpace(x.AgreementLink) ? "未上传" : "有合同").Named("合同");
            column.Buttons(btns => btns.Add(x => Html.ActionLink("编辑", "EditProject", new {id = x.ID}))
                                       .Add(x => Html.ScriptLink("投标列表", "show_detail({0})", x.ID))
                                       .Add(x => Html.ActionLink("上传合同", "Agreement", new { id = x.ID }))
                );
        }).Complex(ViewData)
    <div class="grid_foot">
    </div>
</div>
<div class="blank5">
</div>
@Html.Pager(Model)